package com.example.module_maintenance

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.bw.lib_base.path.RouterPath
import com.bw.lib_base.view.BaseActivity
import com.example.module_maintenance.databinding.ActivityAddRepairBinding
import com.example.module_maintenance.entity.RepairEntity
import com.example.module_maintenance.viewmodel.RepairViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.PATH_ADD_REPAIR_ACTIVITY)
class AddRepairActivity : BaseActivity<ActivityAddRepairBinding>() {


    private val vm by lazy { ViewModelProvider(this)[RepairViewModel::class.java] }

    private val repairBody: RepairEntity = RepairEntity(
        contactMethod = "",
        faultDescription = "",
        faultPhotos = "",
        id = 0,
        orderNumber = "",
        processingStatus = "",
        repairLocation = "",
        repairName = "",
        repairTime = "",
        userId = 1
    )

    override fun initView() {

        mDataBinding.add.setOnClickListener {

            repairBody.repairName = mDataBinding.et1.text.toString()
            repairBody.contactMethod = mDataBinding.et2.text.toString()
            repairBody.repairLocation = mDataBinding.et3.text.toString()
            repairBody.faultDescription = mDataBinding.t4.text.toString()

            vm.addRepair(repairBody)
        }
        vm.addRepairSuccess.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }
        mDataBinding.back.setOnClickListener {
            onBackPressed()
        }
    }




    override fun getLayoutId(): Int = R.layout.activity_add_repair

}